import tensorflow as tf
from tensorflow import keras
from sklearn.datasets import fetch_california_housing
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split
from self_mudle.plot_learning_curves import plot_learning_curves

dataset = fetch_california_housing()
train_x, test_x, train_y, test_y = train_test_split(dataset.data,dataset.target,test_size=0.2,random_state=42)
train_x, valid_x, train_y, valid_y = train_test_split(train_x,train_y,test_size=0.2,random_state=42)

# print(train_x.shape,valid_x.shape,test_x.shape)

scaler = StandardScaler()
train_x = scaler.fit_transform(train_x)
valid_x = scaler.transform(valid_x)
test_x = scaler.transform(test_x)

model = keras.Sequential([
    keras.layers.Dense(16,activation='relu',input_shape = train_x.shape[1:]),
    keras.layers.Dense(1)
])
model.summary()

model.compile( 
    optimizer = keras.optimizers.Adam(0.001),
    loss = keras.losses.mean_squared_error
)

history = model.fit(train_x, train_y, epochs=10, validation_data = (valid_x, valid_y))
model.evaluate(test_x,test_y)
plot_learning_curves(history)
